package kiky.test.myqt;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MyQT extends Activity {
	private Button btn_login,btn_logout;
	private RadioGroup rbg_ip,rbg_id,rbg_pwd;
	private TextView tv_link,tv_data;
	private static String data;
	TextView tv_hello;
	private int finish=0;
	public  SetUIHandler  setUIhandler = new SetUIHandler ();
	 private Thread thread = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_qt);
        tv_hello=(TextView)findViewById(R.id.tv_hello);
      //建構執行緒
        thread = new Thread(){ 
            @Override
            public void run(){ 
                try{
                    
                    //Thread.sleep(3000);
                		
                    Message msg = new Message();
                    msg.what = finish;
                    //setUIhandler.sendMessage(msg);
                    uiMessageHandler.sendMessage(msg);
                }catch (Exception e){
                    e.printStackTrace();
                }finally{
                }
            }
        };
        //開始執行執行緒
        thread.start();
    }
    Handler uiMessageHandler = new Handler(){
    	@Override
        public void handleMessage(Message msg){
    		
    		switch(msg.what)
    		{
    			case 0:
    				 
    				tv_hello.setText("Hello Handler!!");
    				break;
    			
    		}
    	}
    };

    protected void onDestroy() {

        super.onDestroy();



    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_my_qt, menu);
        return true;
    }
    
    /*
    //Setup View Components which we will use later.
    private void setupViewComponent(){
    	btn_login=(Button) findViewById(R.id.btn_login);
    	btn_logout=(Button) findViewById(R.id.btn_logout);
    	rbg_ip=(RadioGroup) findViewById(R.id.rbg_ip);
    	rbg_id=(RadioGroup) findViewById(R.id.rbg_id);
    	rbg_pwd=(RadioGroup) findViewById(R.id.rbg_pwd);
    	tv_link=(TextView) findViewById(R.id.tv_link);
    	tv_data=(TextView) findViewById(R.id.tv_data);
    	// set up Event_listener for buttons
    	btn_login.setOnClickListener(btn_login_onClick);
    	btn_logout.setOnClickListener(btn_logout_onClick);
    }
    */
    /*
  //btn_login_onClick - Action
    private Button.OnClickListener btn_login_onClick=new Button.OnClickListener(){

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			String info= ((RadioButton)findViewById(rbg_ip.getCheckedRadioButtonId())).getText()+
					"ID="+((RadioButton)findViewById(rbg_id.getCheckedRadioButtonId())).getText()+
					"&Password="+((RadioButton)findViewById(rbg_pwd.getCheckedRadioButtonId())).getText()+
					"&Action=login";
			

			tv_link.setText(info);
			if(rbg_ip.getCheckedRadioButtonId()==R.id.rb_ip_1){
				Log.d("Kiky","btn_login_onClick: Do w1");
				//請經紀人指派工作名稱 w1，給工人做				
		       mThreadHandler.post(w1);
			}else{
				Log.d("Kiky","btn_login_onClick: Do w2");
				mThreadHandler.post(w2);
			}
			
		}
    	
    };
    
  //btn_logout_onClick - Action
    private Button.OnClickListener btn_logout_onClick=new Button.OnClickListener(){

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			String info= ((RadioButton)findViewById(rbg_ip.getCheckedRadioButtonId())).getText()+
					"ID="+((RadioButton)findViewById(rbg_id.getCheckedRadioButtonId())).getText()+
					"&Password="+((RadioButton)findViewById(rbg_pwd.getCheckedRadioButtonId())).getText()+
					"&Action=logout";
			tv_link.setText(info);
			if(rbg_ip.getCheckedRadioButtonId()==R.id.rb_ip_1){				
				Log.d("Kiky","btn_logout_onClick: Do w1");
				//請經紀人指派工作名稱 w1，給工人做				
		        mThreadHandler.post(w1);
		        
			}else{
				  Log.d("Kiky","btn_logout_onClick: Do w2");
				mThreadHandler.post(w2);
				
			}
		}
    	
    };
    */
}
